﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TKToXML.Models
{
    public class HopDong : BaseChungTu, IBaseChungTu
    {        
        //public virtual int NamChungTu { get; set; }
        //public virtual int SoChungTu { get; set; }
        public virtual DateTime NgayChungTu { get; set; }
        public virtual int NamTK { get; set; }
        public virtual int SoTK { get; set; }
        public virtual string SoHopDong { get; set; }
        public virtual DateTime NgayHopDong { get; set; }
        public virtual DateTime ThoiHanThanhToan { get; set; }
        public virtual string MaDVKhaiBao { get; set; }
        public virtual string TenDVKhaiBao { get; set; }        
        public virtual string MaPTTT { get; set; }
        public virtual string MaDKGH { get; set; }
        public virtual string DiaDiemGH { get; set; }
        public virtual string MaNguyenTe { get; set; }
        public virtual decimal TriGiaNguyenTe { get; set; }
        public virtual string MaDVMuaHang { get; set; }
        public virtual string TenDVMuaHang { get; set; }
        public virtual string MaDVBanHang { get; set; }
        public virtual string TenDVBanHang { get; set; }
        public virtual DateTime NgayNhapMay { get; set; }
        public virtual string NguoiNhapMay { get; set; }

        public virtual IList<HopDongChiTiet> HopDongChiTiets { get; set; }
        
        public virtual string ToXML()
        { 
            string result = "";
            result += "<ContractDocuments>";
                result += "<ContractDocument>";
                    result += "<reference>" + SoHopDong + "</reference>";
                    result += "<issue>" + NgayHopDong.ToString("yyyy-MM-dd") + "</issue>";
                    result += "<expire>" + ThoiHanThanhToan.ToString("yyyy-MM-dd") + "</expire>";
                    result += "<Payment>";
                        result += "<method>" + MaPTTT + "</method>";
                    result += "</Payment>";
                    result += "<TradeTerm>";
                        result += "<condition>" + MaDKGH + "</condition>";
                    result += "</TradeTerm>";
                    result += "<DeliveryDestination>";
                        result += "<line>" + DiaDiemGH + "</line>";
                    result += "</DeliveryDestination>";
                    result += "<CurrencyExchange>";
                        result += "<currencyType>" + MaNguyenTe + "</currencyType>";
                    result += "</CurrencyExchange>";
                    result += "<totalValue>" + TriGiaNguyenTe.ToString() + "</totalValue>";
                    result += "<Buyer>";
                    result += "<name>" + TenDVMuaHang + "</name>";
                        result += "<identity>" + MaDVMuaHang + "</identity>";
                    result += "</Buyer>";
                    result += "<Seller>";
                        result += "<name>" + TenDVBanHang + "</name>";
                        result += "<identity>" + MaDVBanHang + "</identity>";
                    result += "</Seller>";
                    //Hop dong chi tiet
                    foreach (HopDongChiTiet hdct in HopDongChiTiets)
                    {
                        result += hdct.ToXML();
                    }
                result += "</ContractDocument>";
            result += "</ContractDocuments>";
            return result;
        }
    }
}
